package com.adb.droid.ui;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Toast;

import com.adb.droid.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

/**
 * This is show the address seach in using google map address function
 * 
 * @author bhavdip
 * 
 */
public class MapInputActivity extends FragmentActivity {

	private static final String TAG = MapInputActivity.class.getCanonicalName();
	private Button mbtnCaptureDone;
	private Button mbtnAddressSearch;
	private GoogleMap mMap;
	private AutoCompleteTextView mautotxt;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d(TAG, "onCreate");
		setContentView(R.layout.activity_map_input_screen);
		mbtnCaptureDone = (Button) findViewById(R.id.btn_capture_done);
		mbtnCaptureDone.setOnClickListener(mMapSnapshotListener);
		mbtnAddressSearch = (Button) findViewById(R.id.btn_address_serch);
		mbtnAddressSearch.setOnClickListener(mAddressSearchListener);
		// We only create a fragment if it doesn't already exist.
		setUpMapIfNeeded();
		
//		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line,)
		mautotxt = (AutoCompleteTextView)findViewById(R.id.autotxt_address);
	}

	@Override
	protected void onStart() {
		super.onStart();
		Log.d(TAG, "onStart");
	}

	@Override
	protected void onStop() {
		super.onStop();
		Log.d(TAG, "onStop");
	}

	@Override
	protected void onResume() {
		super.onResume();
		// In case Google Play services has since become available.
		setUpMapIfNeeded();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		Log.d(TAG, "onDestroy");
	}

	private void setUpMapIfNeeded() {
		// Do a null check to confirm that we have not already instantiated the
		// map.
		if (mMap == null) {
			// Try to obtain the map from the SupportMapFragment.
			mMap =((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_address_search))
					.getMap();
			// Check if we were successful in obtaining the map.
			if (mMap != null) {
				setUpMap();
			}
		}
	}

	private void setUpMap() {
		mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title(
				"Marker"));
	}
	
	private OnClickListener mAddressSearchListener = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			Toast.makeText(getApplicationContext(), "Address search",
					Toast.LENGTH_LONG).show();	
		}
	};
	
	private OnClickListener mMapSnapshotListener = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			Toast.makeText(getApplicationContext(), "Done Press",
					Toast.LENGTH_LONG).show();
		}
	};

}
